﻿@model OPM.Models.GetOperating

@{
    var case_id = string.IsNullOrWhiteSpace(Request["case_id"]) ? Request["id"] : Request["case_id"];
    Layout = "~/Views/Shared/_LayoutPopup.cshtml";
    //var sl = new SL();
    //var severities = sl.GetSeverity(Model.severity_id);
    //var listPriorities = sl.GetPriority(Model.priority_id);
    //var secrets = sl.GetSecret(Model.secret_id);
}

@if (ViewBag.ErrorResult != null)
{
    <div style="color: red; font-size: 20px; border: solid 1px red; background-color: rgb(250, 191, 171); margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px">
        @ViewBag.ErrorResult
    </div>
    <div class="dNone">
        <div id="inline_content">
            <div class="SaveSuccess">
                <div class="SaveSuccessTab1">บันทึกข้อมูลแล้ว</div>
                <div class="SaveSuccessTab2">รหัสการให้บริการ : <span>@ViewBag.MessageSuccess</span></div>
                <div class="SaveSuccessTab3" onclick="$.colorbox.close();">@Multi.finish</div>
            </div>
        </div>
    </div>

    <script>
        $(document).ready(function () {
            $.colorbox({
                inline: true,
                width: 300,
                href: "#inline_content",
                fastIframe: false,
                onClosed: function () {
                    parent.parent.$.colorbox.close();
                }
            });
        });
    </script>
}



@using (Html.BeginForm("EditOperating", "GroupList", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="hidden" id="case_id" name="case_id" value="@case_id"/>
    @Html.HiddenFor(m => m.id)
    @Html.HiddenFor(m => m.date_opened)
    @Html.HiddenFor(m => m.date_closed);
    <div class="service_search_header">
        <div class="service_title">@Multi.AddOperation</div>
    </div>

    <div class="service_search_header2">
        <div class="service_title">@Multi.operation_type</div>
    </div>
    <div class="service_box_table">
        <table id="service_table">
            <tr>
                <td>@Multi.operationType</td>
                <td>
                    <a class="formBtn3 dBlock"  data-block="type"
                       href="@Url.Action("OperatingType")?a=type&case_id=@case_id"
                           onclick=" parent.goToPopup2($(this).attr('href'), getForm()); return false; ">@Multi.operationType</a>

                    <span id="block_type">
                        @if (!string.IsNullOrWhiteSpace(Model.operating_type_id))
                        {
                            <input type="hidden" name="type" value="@Model.operating_type_id" />
                            <div class="blockReAction" data-value="@Model.operating_type_id">
                                @Model.operating_type_text
                                <span onclick="removebox('type', '@(Model.operating_type_id)'); "></span>
                            </div>
                        }
                    </span>
                    @* <span id="block_type"></span> *@
                </td>
            </tr>
            <tr>
                <td>@Multi.operatingStatus</td>
                <td><a class="formBtn3 dBlock" data-block="status"
                       href="@Url.Action("OperatingStatus")?a=status&case_id=@case_id"
                       onclick=" parent.goToPopup2($(this).attr('href'), getForm()); return false; ">@Multi.operatingStatus</a>
                    <span id="block_status">
                        @if (!string.IsNullOrWhiteSpace(Model.status_id))
                        {
                            <input type="hidden" name="status" value="@Model.status_id" />
                            <div class="blockReAction" data-value="@Model.status_id">
                                @Model.status_text
                                <span onclick="removebox('status', '@(Model.status_id)'); "></span>
                            </div>
                        }
                    </span>
                    @* <span id="block_status"></span></td>*@
            </tr>
            <tr>
                <td>@Multi.recipient</td>
                <td>
                        <input id="terminal_text" type="text" value="@Model.org_text" name="terminal_text" style="background-color: rgb(214, 214, 214)" readonly>

                    <a href="@Url.Action("SelectTerminal", "GroupList")?a=contact&case_id=@case_id" 
                       data-block="block_contact" class="callBoxContact" 
                       onclick=" parent.goToPopup2($(this).attr('href'), getForm()); return false; ">
                        <div class="search-person"></div>
                        <input type="hidden" name="org_id" id="org_id" value="@Model.org_id" />
                        <input type="hidden" name="cont_id" id="cont_id" />
                    </a>
                </td>
            </tr>
            <tr>
                <td>@Multi.detail</td>
                <td>
                @Html.TextAreaFor(m => m.summary, new { style = "height: 60px" })
            </tr>
            <tr>
                <td>@Multi.file_input</td>
                <td>
                    <input type="file" id="case_attachment_input" />
                    <span id="block_case_attachments"></span>
                </td>
            </tr>
            <tr>
                <td>@Multi.severity_id</td>
                <td>
                    @Html.DropDownListFor(m => m.severity_id, (SelectList)ViewBag.listOfSeverity, "เลือกชั้นความเร่งด่วน")<span style="color: red">*</span>
                </td>
            </tr>
            <tr>
                <td>@Multi.secret_id</td>
                <td>
                    @Html.DropDownListFor(m => m.secret_id, (SelectList)ViewBag.listOfSecret, "เลือกชั้นความลับ")<span style="color: red">*</span>
                </td>
            </tr>
            <tr>
                <td>@Multi.priority_id</td>
                <td>
                    @Html.DropDownListFor(m => m.priority_id, (SelectList)ViewBag.listOfPriority, "เลือกชั้นความสำคัญ")<span style="color: red">*</span>
                </td>
            </tr>
        </table>
    </div>
    <div class="BoxServiceBottom">
        <div class="BoxServiceActionPrev floatL" onclick="parent.$.fn.colorbox.close();">@Multi.Cancel</div>
        <input class="BoxServiceActionNext floatR" type="submit" value="@Multi.save_as" />
        <div class="clear"></div>
    </div>
}
<link rel="stylesheet" type="text/css" href="~/js/colorbox-master/colorbox.css" />
<script src="~/js/colorbox-master/jquery.colorbox-min.js"></script>
<script src="~/js/opm_uploadfile.js"></script>

<script>
    function getForm() {
        var formJson = new Object();

        formJson.case_id = '@case_id';
        formJson.type = $('#type').val();
        formJson.type_text = $('#type_text').val();
        formJson.status = $('#status').val();
        formJson.status_text = $('#status_text').val();
        formJson.org_id = $('#org_id').val();
        formJson.cont_id = $('#cont_id').val();
        formJson.terminal_text = $('#terminal_text').val();
        formJson.summary = $('#summary').val();
        formJson.detail = $('#detail').val();
        formJson.severity_id = $('#severity_id').val();
        formJson.secret_id = $('#secret_id').val();
        formJson.priority_id = $('#priority_id').val();
        formJson.block_case_attachments = $('#block_case_attachments').html();

        return formJson;
    }

    function genDivSelected(type, value, text) {
        var div1 = '<input type="hidden"  id="' + type + '" name="' + type + '" value="' + value + '">' +
            '<input type="hidden"  id="' + type + '_text" name="' + type + '_text" value="' + text + '">' +
                '<div class="blockReAction" data-value="' + value + '">' +
                    text + '<span onclick="removebox(\'' + type + '\', ' + value + ');"></span>' +
                '</div>';
        //alert(div1);
        return div1;
    }
    $(document).ready(function () {

        if (parent.formJson == null) {
            parent.formJson = new Object();
        }

        if (parent.formJson.type) {
            var text2 = genDivSelected('type', parent.formJson.type, parent.formJson.type_text);
            $('#block_type').html(text2);
        }
        if (parent.formJson.status) {
            var text3 = genDivSelected('status', parent.formJson.status, parent.formJson.status_text);
            $('#block_status').html(text3);
        }
        $('#org_id').val(parent.formJson.terminal_org_id);
        $('#cont_id').val(parent.formJson.terminal_officer_id);
        $('#terminal_text').val(parent.formJson.terminal_text);
        $('#summary').val(parent.formJson.summary);
        $('#detail').val(parent.formJson.detail);
        $('#severity_id').val(parent.formJson.severity_id);
        $('#secret_id').val(parent.formJson.secret_id);
        $('#priority_id').val(parent.formJson.priority_id);
        $('#block_case_attachments').html(parent.formJson.block_case_attachments);

    });

</script>
